package com.koron.system.configSettings.post.controller;

import com.koron.bean.base.Response;
import com.koron.bean.query.PageQuery;
import com.koron.bean.system.post.po.PostPo;
import com.koron.common.core.config.ThreadLocalContext;
import com.koron.system.configSettings.post.service.PostService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * (Post)表控制层
 *
 * @author zhouj
 * @since 2022-01-10 09:24:28
 */
@Api(tags = "岗位配置")
@RestController
@RequestMapping("/post/")
public class PostController {

    @Autowired
    private PostService postService;

    private String getCurrDs() {
        return ThreadLocalContext.get().getCurrDs();
    }

    @ApiOperation(value = "新增或修改")
    @PostMapping("insertOrUpdate")
    public Response insertOrUpdate(@RequestBody PostPo post) {
        return Response.ok(postService.insertOrUpdate(post));
    }

    @ApiOperation(value = "新增")
    @PostMapping("insert")
    public Response insert(@RequestBody PostPo post) {
        return Response.ok(postService.insert(post));
    }

    @ApiOperation(value = "批量新增")
    @PostMapping("insertBatch")
    public Response insertBatch(@RequestBody List<PostPo> postList) {
        return Response.ok(postService.insertBatch(postList));
    }

    @ApiOperation(value = "根据id更新")
    @PutMapping("update")
    public Response update(@RequestBody PostPo post) {
        return Response.ok(postService.update(post));
    }

    @ApiOperation(value = "根据id删除")
    @DeleteMapping("deleteById")
    public Response deleteById(String id) {
        return Response.ok(postService.deleteById(id));
    }

    @ApiOperation(value = "根据id查询")
    @GetMapping("queryById")
    public Response queryById(String id) {
        return Response.ok(postService.queryById(id));
    }

    @ApiOperation(value = "不分页查询列表")
    @GetMapping("queryList")
    public Response queryList(PostPo queryVo) {
        return Response.ok(postService.queryList(queryVo));
    }

    @ApiOperation(value = "分页查询列表")
    @GetMapping("queryPageList")
    public Response queryPageList(PostPo queryPo, PageQuery pageQuery) {
        return Response.ok(postService.queryPageList(queryPo, pageQuery));
    }

}
